package com.yanqu.road.dao.impl.activity.tongbing.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.tongbing.config.TongBingCityTypeConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TongBingCityTypeConfigDaoImpl extends TempDao {

    private static String getTongBingCityTypeConfigSql = "select * from `t_s_activity_tongbing_city_type` where `activityId`=?";

    public Map<Integer, TongBingCityTypeConfig> getTongBingCityTypeConfigMap(int activityId) {
        Map<Integer, TongBingCityTypeConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getTongBingCityTypeConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TongBingCityTypeConfig tongBingCityTypeConfig = new TongBingCityTypeConfig();
                tongBingCityTypeConfig.setActivityId(rs.getInt("activityId"));
                tongBingCityTypeConfig.setType(rs.getInt("type"));
                tongBingCityTypeConfig.setIcon(rs.getInt("icon"));
                tongBingCityTypeConfig.setName(rs.getString("name"));
                tongBingCityTypeConfig.setFoodProduction(rs.getInt("foodProduction"));
                tongBingCityTypeConfig.setTeamNum(rs.getInt("teamNum"));
                tongBingCityTypeConfig.setSoldierNum(rs.getInt("soldierNum"));
                tongBingCityTypeConfig.setAddition(rs.getInt("addition"));
                tongBingCityTypeConfig.setBuffEffect(Integer.valueOf(rs.getString("buffEffect")));
                tongBingCityTypeConfig.setCampPoint(rs.getInt("campPoint"));
                tongBingCityTypeConfig.setExtraTeamNum(rs.getInt("extraTeamNum"));
                map.put(tongBingCityTypeConfig.getType(), tongBingCityTypeConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
